package com.wind.lambda;

import java.util.ArrayList;
import java.util.List;

/**
 * Lambda表达式 遍历集合
 *
 * @author Wind
 */
public class LambdaTest07 {
    public static void main(String[] args) {
        List<Star> stars = new ArrayList<>();
        stars.add(new Star(1, "刘德华", true));
        stars.add(new Star(2, "郭富城", true));
        stars.add(new Star(3, "迪丽热巴", false));
        stars.add(new Star(4, "水菜麗", false));
        stars.add(new Star(5, "泷泽萝拉", false));

        // 普通for循环移除元素
        for (int i = 0; i < stars.size(); i++) {
            if (stars.get(i).getId() == 1) {
                stars.remove(stars.get(i));
                break;
            }
        }
        System.out.println(stars);
        System.out.println("----------------------------------");

        // 增强for循环 移除元素
        for (Star star : stars) {
            if (star.getId() == 2) {
                stars.remove(star);
                break;
            }
        }
        System.out.println(stars);
        System.out.println("----------------------------------");

        /*
            Lambda 表达式移除集合元素
         */
        stars.removeIf((t) -> {
            return t.getId() == 3;
        });
        System.out.println(stars);
        System.out.println("----------------------------------");
        // 简化
        stars.removeIf(t -> t.getId() == 5);
        System.out.println(stars);
        System.out.println("----------------------------------");
    }
}